#include <kwdb/client.h>
#include <iostream>
#include <chrono>

int main() {
    kwdb::IngestConfig config;
    config.ingest_endpoint = "127.0.0.1:9090";
    config.timeout_ms = 1000; // 1 second timeout

    kwdb::KwdbClient client(config);
    kwdb::Point point("timeout_test");
    point.add_tag("test", "validation");
    point.add_field("value", 1.0);

    // Start server with delay injection in another terminal:
    // INJECT_DELAY_MS=2000 ./build/server/ingestd/ingestd

    auto start = std::chrono::steady_clock::now();
    auto status = client.write(point);
    auto end = std::chrono::steady_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

    if (!status.ok() && duration < 1500) { // Should timeout around 1000ms
        std::cout << "✅ B.2 & D.1 PASS: Timeout triggered correctly" << std::endl;
        return 0;
    }
    std::cout << "❌ B.2 & D.1 FAIL: Timeout not working properly" << std::endl;
    return 1;
}
